package br.ufrpe.bsi.pvs.xml.response;

import java.util.ArrayList;
import java.util.List;

import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;

import br.ufrpe.bsi.pvs.model.funcionario.Funcionario;
import br.ufrpe.bsi.pvs.model.roupa.Roupa;
import br.ufrpe.bsi.pvs.xml.XMLUtil;

public class ListedResponseProcess implements ResponseProcess {

	@Override
	public Object response(Element response) {
		List<Funcionario> funcionarios = new ArrayList<>();
		
		for (Element funcionarioElement : response.getChildren()) {
			Funcionario f = new Funcionario();

			f.setNome(funcionarioElement.getChild("nome").getValue());
			f.setLogin(funcionarioElement.getChild("login").getValue());
			funcionarios.add(f);
		}

		return funcionarios;
	}

	/** generates a default add request xml document */
	public static Document getListedResponseDocument(String className) {

		Document document = new Document();

		Element root = new Element(XMLUtil.ELEM_ROOT);
		Element response = new Element(XMLUtil.ELEM_RESPONSE);

		Attribute responseName = new Attribute(XMLUtil.ATTR_NAME,
				XMLUtil.LISTED);
		response.setAttribute(responseName);
		
		root.addContent(response);
		document.setRootElement(root);

		return document;
	}
}
